document.write('<script type="text/javascript" src="../static/js/back/utils.js"></script>');
document.write('<script type="text/javascript" src="../static/js/back/ajax.js"></script>');
var _url_ = '../table/addTablesInfo.do';
var _url_edit = '../table/updateTablesInfo.do';
var _url_list = '../order/getOrderProfitList';
var _url_id = '../table/getTablesById';
var _map = {};
var _pageNum = 1;
var _pageNum_ =1;
var _type ;
var spid="";
var _record = 0;
var _startDay;
  $(function(){
	   spid = getCookie("shop_id");
	  _type = getUrlParam("type");
	  var sp  = getUrlParam("shopId");
	  if(sp){
		  spid = sp;
	  }
	  console.log(_type);
	  if(_type === "add"){
		 // getTypeListAdd();
		  _showData = {};
		  $("#shopId").val(spid);
	  }else if(_type === "edit"){
		  showEditData();
		  _url_ = _url_edit;
	  }else{
//		  getTypeList();
		  getList();
	  }
  });
$(function(){
	  $("body").on("click",".mypage span",function(){
		  _pageNum = _pageNum_ = $(this).attr("data-status");
		  if(_record == 1 ){
			  showRecord();
		  }else{
			  getList();
		  }
	  });
	  $(".search-btn").click(function(){
			 var start =  $("#start").val();
			 var end =  $("#end").val();
			 if(end){
				 end = addDate(end,1);
			 }
			 console.log(end);
			 _map['startTime'] = start;
			 _map['endTime'] = end;
			 var _stype =  $("#shopType").val();
			 _map['shopType'] = _stype;
			 _pageNum = 1;
			 getList();
	  });
	  $("body").on("click",".tix-record",function(){
		  var p = $(this).attr('pric');
		  var d = $(this).attr('date');
		  $(".date").text(d+" 账单 ");
		  $(".pric").text("￥"+p);
		  _pageNum_ = 1 ;
		  _startDay = d ;
		  showRecord(_startDay);
		  $(".x-body.one").hide();
		  $(".x-body.two").show();
	  });
		 
});
  function getList(){
	  _map['shopId'] = spid;
	  _map['pageNum'] = _pageNum;
	  _ajax_get_token(_url_list,_map,function(res){
		  console.log(res);
		  console.log(res.returnObject);
		  if(!res.returnObject||res.returnObject.length<=0 ){
			  $(".layui-table tbody").html("");
			  $(".no-more-data").show();
			  $(".mypage").hide();
			  return;
		  }else{
			  $(".mypage").show();
			  $(".no-more-data").hide();
		  }
		  var html = "";
		  var stat = "" , statHtml = "";
		  showPageInfo(res.returnObject);
		  $(".x-right").text("共有数据："+res.returnObject.total +" 条");
		  var startRow = res.returnObject.startRow;
		  var html,stat,statStr,typeStr,sendTypeStr;
		  $.each(res.returnObject.list,function(i,v,arr){
			  
//			  if(v.tranType == 1){
//				  typeStr = "外卖订单";
//			  }else if(v.tranType == 2){
//				  typeStr = "余额提现";
//			  }
//			  
//			  if(v.type == 1){
//				  typeStr+="退换";
//			  }
//			  if(v.status == 1){
//				  statStr = "通过";
//			  }else if (v.status == 2) {
//				  statStr = "拒绝";
//			  }else {
//				  statStr = '待审核';
//			  }
			  html+=' <tr><td>'
// 	             +' <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="'+v.id+'" ><i class="layui-icon">&#xe605;</i></div>'
// 	             +' </td>                                                                                                                  '
// 	             +' <td>'
 	             +(startRow+i)+'</td>                                                                                                             '
 	             +' <td>'+v.date
 	             +'</td>                                                                                           '
 	             +' <td>'+(v.sun/100).toFixed(2)
 	             +'</td>                                                                                           '
 	             +' <td>'+(v.wxp/100).toFixed(2)
 	             +'</td>                                                                                           '
 	             +' <td>'+(v.xxp/100).toFixed(2)
 	             +'</td>'
			  	 +' <td class="td-manage">';
// 	             +' <td align="center"><a target="_blank" href="'+v.adUrl+'"><img  src="'+v.adPic+'" height=50 widht=50 ></a></td>                                                                                                      '
// 	             +' <td>'+v.adUrl+'</td>                                                                                                      '
// 	             +' <td>'+typeStr+'</td>                                                                                                      '
// 	             +' <td >'+(v.type ==1 ? "- " : "+  ") +(v.amount / 100).toFixed(2)+'</td>'
// 	             +' <td >'+statStr+'</td>'
			  	if(v.sun != 0){
			  		html+='   <a title="查看" date ="'+v.date+'" pric = "'+(v.sun/100).toFixed(2)+'" class="tix-record"  onclick="" href="javascript:;">                       '
			  		+'           查看                                                                         '
			  		+'   </a>';
			  	}
	            html+='</td> </tr>';
		  });
		  $(".one .layui-table tbody").html(html);
	  });
  }

function showRecord(d){
	console.log(d);
	_map = {};
	 _map['shopId'] = spid;
	  _map['pageNum'] = _pageNum_;
	  if(d){
		  _map['startDate'] = d;
	  }else{
		  _map['startDate'] = _startDay;
	  }
	  console.log(_startDay);
	  _record = 1 ;
	  _ajax_get_token('../order/getOrdersList',_map,function(res){
		  console.log(res);
		  console.log(res.returnObject);
		  if(!res.returnObject||res.returnObject.length<=0 ){
			  $(".layui-table tbody").html("");
			  $(".no-more-data").show();
			  $(".mypage").hide();
			  return;
		  }else{
			  $(".mypage").show();
			  $(".no-more-data").hide();
		  }
		  var html = "";
		  var stat = "" , statHtml = "";
		  showPageInfo(res.returnObject);
		  var startRow = res.returnObject.startRow;
		  var html,stat,statStr,typeStr="",sendTypeStr;
		  $.each(res.returnObject.list,function(i,v,arr){
			  console.log(v);
			  if(v.payType == 1){
				  typeStr = "微信支付";
			  }else if(v.payType == 2){
				  typeStr = "现金结算";
			  }
			  html+=' <tr><td>'
//	             +' <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="'+v.id+'" ><i class="layui-icon">&#xe605;</i></div>'
//	             +' </td>                                                                                                                  '
//	             +' <td>'
	             +formatDate(v.createTime,'YY-MM-DD')+" # "+(i+startRow)+'</td>                                                                                                             '
	             +' <td>'+(v.type == 1? "外卖" : "堂食")
	             +'</td>                                                                                           '
//	             +' <td align="center"><a target="_blank" href="'+v.adUrl+'"><img  src="'+v.adPic+'" height=50 widht=50 ></a></td>                                                                                                      '
//	             +' <td>'+v.adUrl+'</td>                                                                                                      '
	             +' <td >'+(v.payPrice / 100).toFixed(2)+'</td>'
	             +' <td >'+typeStr+'</td>'
	             +' </tr>';
		  });
		  $(".two .layui-table tbody").html(html);
	  });
}